// 字段名与中文标签的映射对象
const fieldLabels = {
  // "day_energy": "当日获得能源",
  // "day_material": "当日获得建筑材料",
  // "car_num": "解锁车辆数量",
  // "max_car_stage": "最大车辆阶段",
  'item7': '纯净能量',
  'item5': '源器晶石',
  'item8': '合金钢块',
  'item18': '联赛币',
  'item30': '鎏金凭证',
  'item11': '白银凭证',
  'item24': '联盟币',
  'item308011': '农场积分',
  'item28': '友情点',
  'town': '重建计划', // 重建计划
  'explore_stars': '海底星星',
  'relic_remain_count': '遗迹次数',
  'relic_buy_count': '遗迹购买',
  'arena_score': '联赛积分',
  'arena_remain_count': '联赛次数',
  'arena_buy_counts': '联赛购买',
  'arena_box_points': '联赛宝箱值',
  'fishing_level': '捕鱼等级',
  'fishing_bullet_counts': '捕鱼子弹',
  'fishing_picture_count': '捕鱼图鉴',
  'fossil_level': '化石等级',
  'friend_counts': '好友数量',
  'receive_gift_counts': '收礼次数',
  'item14': '流光星晷',
  'item12': '白银宝匣',
  'item13': '太阳金匣',
  'high_draw_guarantee_remain': '高级召唤未中次数',
  'limit_draw_guarantee_remain': '限定召唤未中次数',
  'draw_wish_score': '心愿分数',
  'energy_furnace_level': '能源炉等级',
  'energy_furnace_stone_counts': '能源炉矿石',
  'farm_level': '农场等级',
  'farm_plot_count': '农场地块',
  'camp_level': '主营地等级',
  'building_materials_factory_level': '建材厂等级',
  'building_materials_factory_produce_level': '建材厂产能等级',
  'building_materials_factory_dispatches': '建材厂派遣',
  'bio_lab_level': '生物实验室等级',
  'bio_lab_quick_produce': '生物实验室快速生产',
  'bio_lab_dispatches': '生物实验室派遣',
  'weapon_lab_level': '源器中心等级',
  'weapon_lab_quick_produce': '源器中心快速生产',
  'weapon_lab_dispatches': '源器中心派遣',
  'armor_lab_level': '装备中心等级',
  'armor_lab_quick_produce': '装备中心快速生产',
  'armor_lab_dispatches': '装备中心派遣',
  'water_center_dispatches': '水电中心派遣',
  'water_center_produce': '水电中心产量',
  'wind_center_dispatches': '风电中心派遣',
  'wind_center_produce': '风电中心产量',
  'sunny_center_dispatches': '光电中心派遣',
  'sunny_center_produce': '光电中心产量'
}
const copys = [
  { field: 'technology_progress', label: '科技{i}进度', count: 4 },
  { field: 'bio_lab_member', label: '生物实验室员工', count: 4 },
  { field: 'weapon_lab_member', label: '源器中心员工', count: 4 },
  { field: 'armor_lab_member', label: '装备制造中心员工', count: 4 },
  { field: 'water_level', label: '水电{i}站等级', count: 4 },
  { field: 'water_produce_level', label: '水电{i}站产能等级', count: 4 },
  { field: 'wind_level', label: '风电{i}站等级', count: 4 },
  { field: 'wind_produce_level', label: '风电{i}站产能等级', count: 4 },
  { field: 'sunny_level', label: '光电{i}站等级', count: 4 },
  { field: 'sunny_produce_level', label: '光电{i}站产能等级', count: 4 },
  { field: 'car_lineup', label: '车队{i}阵容', count: 3 },
  { field: 'car_fight', label: '车队{i}战力', count: 3 },
  { field: 'car_durable', label: '车队{i}护盾', count: 3 },
  { field: 'car_ammo', label: '车队{i}弹药', count: 3 },
  { field: 'car_load', label: '车队{i}载重', count: 3 },
  { field: 'car_stage', label: '车队{i}阶级', count: 3 },
  { field: 'car_strengthen', label: '车队{i}强化', count: 3 }
]
const copyOptions = {}
for (const copy of copys) {
  for (let i = 1; i <= copy.count; i++) {
    const one = { ...copy }
    delete one.count
    one.field += i

    if (one.label.includes('{i}')) {
      one.label = one.label.replace(/{i}/g, i)
    } else {
      one.label += i
    }
    fieldLabels[one.field] = one.label
    const prefix = one.field.split('_')[0]
    copyOptions[one.field] = { 'group': 'copy_' + prefix }
  }
}

const baseData = [
  { prop: 'update_time', label: '更新时间', width: '140', fixed: true, align: 'center' },
  { prop: 'sid', label: '服务器', width: '70', align: 'center' },
  { prop: 'account', label: '账号', width: '160', fixed: true, align: 'center' },
  { prop: 'actor_id', label: '角色ID', width: '120', fixed: true, align: 'center' },
  { prop: 'actor_name', label: '角色名', width: '120', fixed: true, align: 'center' },
  {
    prop: 'status', label: '状态', align: 'center', width: '70',
    tag: 'el-tag'
  },
  {
    prop: 'is_online', label: '在线', align: 'center', width: '70',
    tag: 'el-tag'
  },
  { prop: 'sex', label: '性别', align: 'center', width: '40', formatter: row => {if (Object.keys(row).length === 0) return '';if (row.sex === 1) return '女';if (row.sex === 0) return '男';return '未知';} },
  { prop: 'create_dt', label: '创角时间', width: '135', align: 'center' },
  { prop: 'login_dt', label: '最近登录时间', width: '135', align: 'center' },
  { prop: 'logout_dt', label: '最近登出时间', width: '135', align: 'center' },
  { prop: 'level', label: '等级', width: '55', align: 'center', sortable: 'custom' },
  { prop: 'item9', label: '声望', width: '100', align: 'center', sortable: 'custom' },
  { prop: 'vip', label: 'VIP', width: '50', align: 'center', sortable: 'custom' },
  { prop: 'vip_exp', label: 'VIP经验', width: '100', align: 'center', sortable: 'custom' },
  { prop: 'total_amount', label: '充值', width: '75', align: 'center', sortable: 'custom' },
  { prop: 'real_amount', label: '真实充值', width: '85', align: 'center', sortable: 'custom' },
  { prop: 'power', label: '战力', width: '90', align: 'center', sortable: 'custom' },
  { prop: 'diamond', label: '钻石', width: '80', align: 'center', sortable: 'custom' },
  { prop: 'energy_speed', label: '能源产速', width: '90', align: 'center', sortable: 'custom' },
  { prop: 'energy', label: '能源', width: '90', align: 'center', sortable: 'custom' },
  // { prop: 'oxygen', label: '氧气', width: '90', align: 'center', sortable: 'custom' },
  { prop: 'material', label: '建材', width: '90', align: 'center', sortable: 'custom' },
  { prop: 'food', label: '晶币', width: '90', align: 'center', sortable: 'custom' },
  { prop: 'card_experience', label: '卡牌经验', width: '95', align: 'center', sortable: 'custom' },
  { prop: 'voucher_inner', label: '秘券', width: '70', align: 'center', sortable: 'custom' },
  { prop: 'voucher_inner_limit', label: '限时秘券', width: '80', align: 'center', sortable: 'custom' },
  { prop: 'voucher_outer', label: '代金券', width: '70', align: 'center', sortable: 'custom' },
  { prop: 'voucher_outer_limit', label: '限时代金券', width: '90', align: 'center', sortable: 'custom' },
  { prop: 'guide_event_id', label: '新手引导', width: '70', align: 'center', sortable: 'custom' },
  { prop: 'main_task_id', label: '主线任务', width: '70', align: 'center', sortable: 'custom' },
  { prop: 'explore_level_id', label: '海底关卡', width: '70', align: 'center', sortable: 'custom' },
  { prop: 'relic_level_id', label: '遗迹关卡', width: '70', align: 'center', sortable: 'custom' },
  { prop: 'underground_explore', label: '地心勘探层数', width: '80', align: 'center', sortable: 'custom' },
  { prop: 'arena_rank', label: '海岛联赛名次', width: '80', align: 'center', sortable: 'custom' },
  { prop: 'hero_num', label: '英雄人数', width: '70', align: 'center', sortable: 'custom' },
  { prop: 'best_hero_ids', label: '最强5人', width: '180', align: 'center' }, // "best_hero_ids": "最强5人ID",
  { prop: 'red_hero_num', label: '红卡人数', width: '80', align: 'center' },
  { prop: 'orange_hero_count', label: '橙卡人数', width: '80', align: 'center' },
  { prop: 'union_id', label: '联盟', width: '90', align: 'center', sortable: 'custom' },
  { prop: 'total_online_time', label: '累计时长', width: '80', align: 'center', sortable: 'custom' }
]
const otherData = []
const endData = [
  { prop: 'cid', label: '注册渠道', width: '70', align: 'center' },
  { prop: 'game_id', label: '注册包', width: '70', align: 'center' },
  { prop: 'login_platform', label: '登录渠道', width: '70', align: 'center' },
  { prop: 'login_game_id', label: '登录包', width: '70', align: 'center' }
]
/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default function getActorField(is_log, is_otherData) {
  console.log('actor.js:is_log:' + is_log + ',is_otherData:' + is_otherData)
  const addFields = handleFieldFields()
  const tbaseData = baseData.map(item => {
    return {
      ...item,
      group: 'base'
    }
  })
  let allColumns = []
  if (is_log) {
    allColumns = [
      ...tbaseData
    ]
    allColumns.unshift({ prop: 'log_date', label: '记录时间', width: '140', fixed: true, align: 'center', 'group': 'log' })
  } else {
    allColumns = [
      ...tbaseData
    ]
  }
  allColumns = allColumns.concat(addFields)
  if (is_otherData) {
    allColumns = allColumns.concat(otherData)
  }
  allColumns = allColumns.concat(endData)
  return allColumns
}
function handleFieldFields() {
  const fieldList = Object.keys(fieldLabels)
  // 自动生成 addFields 数组
  let options = {
    'update_time': { width: '140' },
    'high_draw_guarantee_remain': { width: '60' },
    'limit_draw_guarantee_remain': { width: '60' },
    'bio_lab_dispatches': { width: '110' },
    'weapon_lab_dispatches': { width: '110' },
    'water_center_dispatches': { width: '140' },
    'wind_center_dispatches': { width: '140' },
    'sunny_center_dispatches': { width: '140' },
    'fishing_bullet_counts': { width: '140' },
    'building_materials_factory_dispatches': { width: '140' },
    'energy_furnace_stone_counts': { width: '140' },
    'armor_lab_dispatches': { width: '110' },
    'water_center_produce': { width: '85' },
    'wind_center_produce': { width: '85' },
    'sunny_center_produce': { width: '85' },
    'energy_furnace_level': { width: '80' },
  }
  for (let i = 1; i <= 4; i++) {
    options['car_load' + i] = { formatter: row => ('' + (row['car_load' + i] / 100 || 0) + '%') } // 车队{i}载重
  }
  for (let i = 1; i <= 3; i++) {
    options['car_lineup' + i] = { width: '180' } // 车队{i}载重
    options['car_fight' + i] = { width: '85' } // 车队{i}战力
  }
  for (const key in copyOptions) {
    if (Object.prototype.hasOwnProperty.call(options, key)) {
      options[key] = { ...options[key], ...copyOptions[key] }
    } else {
      options[key] = copyOptions[key] 
    }
  }
  const addFields = fieldList.map(prop => {
    let width = fieldLabels[prop].length * 15
    if (width > 70) width = 70
    if (prop.startsWith('item')) {
      width = '90'
    }
    const label = fieldLabels[prop]
    return {
      prop,
      label: label,
      width: width,
      align: 'center',
      ...(options[prop] || {})
    }
  })
  return addFields
}
